package cn.web.management.service.general;

import cn.web.management.dao.impl.FindAllImpl;
import cn.web.management.dao.inface.FindAllDao;
import cn.web.management.domain.DepartmentInform;
import cn.web.management.domain.GroupInform;
import cn.web.management.domain.PersonalInform;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.List;
import java.util.Map;

public class MyOfficePage {
    private FindAllDao findAllDao = new FindAllImpl();
    /**
     * @description: 根据员工号返回部门信息
     * @paramName: [employno]
     * @paramType: [java.lang.String]
     * @returnType: java.lang.String
     */
    public String findDepartmentInform(String employno){
        Map<String, Object> personalInform = findAllDao.findPersonalInform(employno);
        String groupno = (String) personalInform.get("groupno");

        List<GroupInform> groupInform = findAllDao.findGroupInform(groupno);
        String departmentno = groupInform.get(0).getDepartmentno();

        List<DepartmentInform> departmentInform = findAllDao.findDepartmentInform(departmentno);
        String s = "{";
        String department_name = departmentInform.get(0).getDepartment_name();
        String department_introduction = departmentInform.get(0).getDepartment_introduction();
        s += "\"department_name\": \""+department_name+"\",";
        s += "\"department_introduction\": \""+department_introduction+"\"}";
        return s;
    }

    /**
     * @description: 根据员工号返回小组信息
     * @paramName: [employno]
     * @paramType: [java.lang.String]
     * @returnType: java.lang.String
     */
    public String findGroupInform(String employno){
        Map<String, Object> personalInform = findAllDao.findPersonalInform(employno);
        String groupno = (String) personalInform.get("groupno");

        List<GroupInform> groupInform = findAllDao.findGroupInform(groupno);
        String s = "{";
        s += "\"group_name\":\""+groupInform.get(0).getGroup_name()+"\",";
        s += "\"group_introduction\":\""+groupInform.get(0).getGroup_introduction()+"\"}";
        return s;
    }

    /**
     * @description: 查询同组同事信息
     * @paramName: [employno]
     * @paramType: [java.lang.String]
     * @returnType: java.lang.String
     */
    public String findColleagues(String employno){
        Map<String, Object> personalInform = findAllDao.findPersonalInform(employno);
        List<PersonalInform> groupno = findAllDao.findGroupPersonalInform((String) personalInform.get("groupno"));
        ObjectMapper mapper = new ObjectMapper();
        String s = "";
        try {
            s = mapper.writeValueAsString(groupno);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return s;
    }
}
